<?php

/**
 * Profile models
 *
 * Profile models in bundles
 *
 * PHP Version: 1.2.3
 *
 * @author Johari <joharijumali@gmail.com>
 */

namespace Admin\Models\User;

use \Laravel\Database\Eloquent\Model as Eloquent;
use Laravel\Validator as Validator;
use Admin\Models\User\User as User;

/**
 * Data Profile Model Class
 *
 * Create model class for lookup data
 *
 * @author Johari <joharijumali@gmail.com>
 */

class Profile extends Eloquent
{

	public static $timestamps = false;
	public static $table = 'sys_user_profile';
	public static $key = 'sup_id';
	public static $rules = array(
				    		'sup_emel' => 'required|email|unique:sys_user_profile', 
				    		'icno' => 'required|Numeric',
				    		'fullname' => 'required'
				    	);
	
	/**
     * Function validate that pass parameter
     *
     * @param varchar $data the varchar to quote
	 *
	 * @return parameter.
     */
	public static function validate($data)
	{
		return Validator::make($data, Static::$rules);
	}
	
	/**
     * Function user
	 *
	 * @return user.
     */
	public function user()
	{
		return $this->belongs_to('Admin\Models\User\User', 'userid');
	}

	/**
     * Function loggedprofile
	 *
	 * @return loggedprofile.
     */
    public static function loggedprofile()
	{
     	$logged_user = Auth::user();
     	$userInfo = User::find($logged_user->userid)->userprofile;

        $data['sup_id'] = $userInfo->sup_id;
        $data['sup_name'] = $userInfo->sup_name;
        $data['sup_no_ic'] = $userInfo->sup_no_ic;
        $data['sup_emel'] = $userInfo->sup_emel;


        return json_encode($data);
    }

}

?>